$(function () {
    $('#inputCover').on('input', function () {
        $('.article_cover').attr('src', URL.createObjectURL(this.files[0]));
    });


    $.ajax({
        type: 'get',
        url: 'http://localhost:8080/api/v1/admin/category/list',
        success: function (backData) {
            $('.category').html(template('tpl-category', backData.data));
        }
    });


    $('.jebtns').on('click', function () {
        jeDate(
            '#testico', {
                trigger: false,
                format: 'YYYY-MM-DD',
                // theme: {
                //     bgcolor: "#6a8",
                //     pnColor: "#9f0"
                // },
                zIndex: 20001,
            }
        )
    });


    const E = window.wangEditor
    const editor = new E('#wantext')
    editor.create()


    $('.form-group button').on('click', function (event) {
        event.preventDefault();
        let state;
        let fd = new FormData(document.querySelector('#form'));
        if ($(this).html() == '发布') {
            state = '已发布';
        } else {
            state = '草稿';
        }
        fd.append('content', editor.txt.html());
        fd.append('state', state);


        // console.log(fd.get('title'));
        // console.log(fd.get('state'));
        // console.log(fd.get('cover'));
        // console.log(fd.get('categoryId'));
        // console.log(fd.get('date'));
        // console.log(fd.get('content'));


        $.ajax({
            type: 'post',
            url: 'http://localhost:8080/api/v1/admin/article/publish',
            data: fd,
            contentType: false,
            processData: false,
            success: function (backData) {
                alert(backData.msg)
                if (backData.code == 200) {
                    window.location.href = './article_list.html'
                }
            }
        });




    })
})